//成为vip的Layer
gpNamespace.CwvipLayer = cc.Layer.extend({
	
	ctor:function(){
		this._super();
		this.init();
	},

	init:function(){
		cc.spriteFrameCache.addSpriteFrames(gpNamespace.pdkcwvipRes.Pdkcwvip_plist);
		var size = cc.winSize;
		var y=100;
		
		var vip_bg =new cc.Sprite(gpNamespace.cwvip.Cwvip_Bg);
		vip_bg.attr({
			x: size.width/2,
			y: size.height/2+30
		});
		this.addChild(vip_bg);
		
		var by_Bt1 = new cc.MenuItemSprite(
				new cc.Sprite(gpNamespace.cwvip.Cwvip_Bt),
				new tyNamespace.maskSprite(gpNamespace.cwvip.Cwvip_Bt),
				this.tobeVip,
				this);
		by_Bt1.setUserData(35);
		by_Bt1.setPosition(320, y);

		var by_Bt2 = new cc.MenuItemSprite(
				new cc.Sprite(gpNamespace.cwvip.Cwvip_Bt),
				new tyNamespace.maskSprite(gpNamespace.cwvip.Cwvip_Bt),
				this.tobeVip,
				this);
		by_Bt2.setUserData(36);
		by_Bt2.setPosition(by_Bt1.getPositionX()+325, y);

		var by_Bt3 = new cc.MenuItemSprite(
				new cc.Sprite(gpNamespace.cwvip.Cwvip_Bt),
				new tyNamespace.maskSprite(gpNamespace.cwvip.Cwvip_Bt),
				this.tobeVip,
				this);
		by_Bt3.setUserData(37);
		by_Bt3.setPosition(by_Bt2.getPositionX()+322, y);
		
		var byMebu =new cc.Menu(by_Bt1,by_Bt2,by_Bt3);
		byMebu.x = 0;
		byMebu.y = 0;
		byMebu.anchorX = 0;
		byMebu.anchorY = 0;
		this.addChild(byMebu);
	},
	tobeVip:function(sender){
		gpNamespace.SoundManager.playEffect(gpNamespace.soundRes.ButtonEffect, false);
		var goodsId = sender.getUserData();
		var canBuy = true;
		switch (goodsId) {
		case 35:
			if(userInfo.diamond < 70){
//				this.fadeInThenOut("钻石不足!");
				tyNamespace.warningJumper(1,tyNamespace.WarningSectencesIndex.NoDiamond);
				canBuy = false;
			}
			break;
		case 36:
			if(userInfo.diamond < 280){
//				this.fadeInThenOut("钻石不足!");
				tyNamespace.warningJumper(1,tyNamespace.WarningSectencesIndex.NoDiamond);
				canBuy = false;
			}
			break;
		case 37:
			if(userInfo.diamond < 3000){
//				this.fadeInThenOut("钻石不足!");
				tyNamespace.warningJumper(1,tyNamespace.WarningSectencesIndex.NoDiamond);
				canBuy = false;
			}
			break;

		default:
			break;
		}
		if(canBuy){
			cc.log("vipid："+goodsId);
			xinyou.netManager.buyGoodsDj(goodsId,1);
		}
	},
	fadeInThenOut: function(String){
		var stringTTF = new cc.LabelTTF(String, "Arial", 25);
		stringTTF.setFontFillColor(cc.color.WHITE,128);
		stringTTF.attr({
			x:cc.winSize.width/2,
			y:40
		});
		stringTTF.setOpacity(0);
		this.addChild(stringTTF,10);
		stringTTF.runAction(new cc.FadeTo(0.5,255));
		this.scheduleOnce(function(){
			stringTTF.runAction(new cc.FadeOut(1));
		},1);
	},
	
	
});